import {ref} from 'vue'
import http from '@/utils/request'

// 定义所有需要的变量并添加类型注解
const msg = ref<string>('Hello World')
const count = ref<number>(0)
const isLoading = ref<boolean>(false)
const testResponse = ref<string>('')

// 定义fetchTest函数并添加返回类型
const fetchTest = async (): Promise<void> => {
  isLoading.value = true
  try {
    const data = await http.get('/test', {params: {wd: 'vue3'}})
    testResponse.value = `请求成功: ${data} `
  } catch (error: any) {
    testResponse.value = `请求失败: ${error.message}`
  } finally {
    setTimeout(() => {
      isLoading.value = false
    }, 1000)
  }
}

// 导出所有需要在模板中使用的变量和函数
export {msg, count, isLoading, testResponse, fetchTest}